package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.entity.model.OperationLog;
import com.blacktry.entity.model.request.LogRequest;
import com.blacktry.service.OperationLogService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2022-01-25
 */
@Api(value = "操作日志模块", tags = "操作日志接口")
@RestController
@RequestMapping("/operation-log")
public class OperationLogController {

    @Autowired
    private OperationLogService operationLogService;

    @OperLog(operModul = "操作日志-分页查看操作日志", operType = OprLogConst.SELECT, operDesc = "分页查看操作日志")
    @ApiOperation("分页查看操作日志")
    @PostMapping("/selectOperationLog/{page}/{size}")
    public ApiResult<Page<OperationLog>> selectOperationLog(@RequestBody LogRequest logRequest, @DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size){
        Page<OperationLog> logPage = new Page<>(page,size);
        return ApiResultHandler.buildApiResult(200, "请求成功！", operationLogService.selectOperationLog(logRequest,logPage));
    }

    @OperLog(operModul = "操作日志-分页查看操作日志", operType = OprLogConst.SELECT, operDesc = "分页查看操作日志")
    @ApiOperation("查看详细的操作日志")
    @GetMapping("/selectOneOperationLog/{id}")
    public ApiResult<OperationLog> selectOperationLog(@PathVariable("id") String id){
        return ApiResultHandler.buildApiResult(200, "请求成功！", operationLogService.getById(id));
    }
}

